//
//  UIViewController+BKScrollPageController.m
//  bestkeep
//
//  Created by utouu666 on 17/2/16.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "UIViewController+BKScrollPageController.h"
#import "BKScrollPageViewDelegate.h"
#import <objc/runtime.h>
char BKIndexKey;

@implementation UIViewController (BKScrollPageController)
- (UIViewController *)zj_scrollViewController {
    UIViewController *controller = self;
    while (controller) {
        if ([controller conformsToProtocol:@protocol(BKScrollPageViewDelegate)]) {
            break;
        }
        controller = controller.parentViewController;
    }
    return controller;
}

- (void)setZj_currentIndex:(NSInteger)zj_currentIndex {
    objc_setAssociatedObject(self, &BKIndexKey, [NSNumber numberWithInteger:zj_currentIndex], OBJC_ASSOCIATION_ASSIGN);
}

- (NSInteger)zj_currentIndex {
    return [objc_getAssociatedObject(self, &BKIndexKey) integerValue];
}

@end
